package main

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"net/http"
)

func main() {
	r := gin.Default()

	r.MaxMultipartMemory = 8 << 20
	r.POST("/upload", func(context *gin.Context) {
		from, err := context.MultipartForm()
		if err != nil {
			context.String(http.StatusBadRequest, fmt.Sprintf("get err %s", err.Error()))
			return
		}
		// 获取所以图片
		files := from.File["files"]
		for _, file := range files {
			err := context.SaveUploadedFile(file, "./day12_gin/demo5_upload_file/"+file.Filename)
			if err != nil {
				context.String(http.StatusBadRequest, fmt.Sprintf("upload err %s", err.Error()))
				return
			}
		}
		context.String(200, fmt.Sprintf("upload ok %d files", len(files)))
	})
	r.Run(":8000")

}
